﻿using CommonTools;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Threading;
using Language;
using HY_DynamicPassword;
namespace StationDemo.FrameUI
{
    public partial class Form_HYLogin : Form
    {
        public Form_HYLogin()
        {
            InitializeComponent();

            ectUser.Items.Clear();

            for (int i = 0; i < sys.g_listUser.Count; i++)
            {
                ectUser.Items.Add(sys.g_listUser[i]._userName);
            }

            ectUser.SelectedIndex = 0;
            LanguageHelp.GetInstance().Function_FormRegist(this);
            LanguageHelp.GetInstance().Funtion_TransLate(this.Name);
        }

        private void Form_HYLogin_Load(object sender, EventArgs e)
        {

        }

        private void btnLogin_Click(object sender, EventArgs e)
        {
            if (etcPassword.Text == "")
            {
                MessageBox.Show("密码为空，错误", "Err", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            foreach (var temp in sys.g_listUser)
            {
               if (ectUser.Text == temp._userName)
                {
                    if (temp._userPassWord == etcPassword.Text)
                    {
                        this.DialogResult = DialogResult.OK;
                        sys.g_User = temp;
                        this.Close();
                        return;
                    }
                    else
                    {
                        MessageBox.Show("密码错误", "Err", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        //this.Close();
                        return;
                    }
                }
            }
            MessageBox.Show("没有此用户", "Err", MessageBoxButtons.OK, MessageBoxIcon.Error);
            this.Close();
        }

        private void btnCencel_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
